package com.itheima.web.controller;



import com.itheima.domain.Comment;
import com.itheima.domain.Movies;

import com.itheima.service.CommentService;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class SingleController {

    /**
     * 前台根据id进行查询就是找到movie
     */
    @Autowired
    MoviesService moviesService;

    @GetMapping("/movies/findByMovies")
    @ResponseBody
    public Movies findByMovies(Integer id){
     return    moviesService.findByMovies(id);
    }

    @Autowired
    CommentService commentService;
    @GetMapping("/comment/findByComment")
    @ResponseBody
    public List<Comment> findByComment(Integer id){
         return commentService.findByComment(id);
    }



    @PostMapping("/comment/savaComment")
    @ResponseBody
    public String saveComment(@RequestBody Comment comment){
        comment.setTime(new Date());
        comment.setCreatorName("匿名");
        commentService.saveComment(comment);
        return "ok";
    }
}
